package com.springboot.manager.mybatisPlus;

import com.github.yitter.contract.IdGeneratorOptions;
import com.github.yitter.idgen.YitIdHelper;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @version v1.0
 * @ProjectName: manager
 * @ClassName: IdGeneratorOptions
 * @Description: TODO(一句话描述该类的功能)
 * @Author: zhangzl
 * @Date: 2021-07-14 8:40
 */
@Configuration
public class IdGeneratorConfig {

    @Value("${snowflake.workerId}")
    private short workerId;

    @Bean
    public IdGeneratorOptions initMachineId() throws Exception {
        IdGeneratorOptions options = new IdGeneratorOptions(workerId);
        YitIdHelper.setIdGenerator(options);
        return options;
    }
}
